#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repp(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a-1;i>=b;--i)
#define pper(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
#define inf 0x7fffffff
#define inff 0x7fffffffffffffff
#define all(x) x.begin(),x.end()
const int mod = 998244353;
inline int rd(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')f=-f;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=x*10+(ch^48);
		ch=getchar();
	}
	return x*f;
}
ll pw(ll x,int d){
	ll t=1;
	for(;d;d>>=1,x=x*x%mod)if(d&1)t=t*x%mod;
	return t;
}
#define MAX (1<<17)+5
int ya[MAX];
int a[MAX];
int c[MAX];
vector<int> d[23];
int sz[30];
int X[4];
vector<vector<array<int,4> > > dp[23];// <l,r,val>
vector<int> alltm[23],unival[23];
ll ans[MAX];
int premx[MAX];
int K,lim;
int n,m;
void solve(){
	rep(i,0,K){
		premx[i] = i+1;
	}
	// rep(i,0,n){
	// 	cout<<a[i]<<' ';
	// }cout<<endl;
	rep(i,0,K){
		alltm[0][i] = 0;
		unival[0][i] = i;
		dp[0][i].clear();
		dp[0][i].pb({0,1,a[i],i});
	}
	rep(i,0,K)ans[i] = 0;

	repp(i,1,lim){
		rep(j,0,sz[i]){
			dp[i][j].clear();
			int ls = j*2;
			int rs = j*2+1;
			if(d[i][j]==0){
				for(auto itm : dp[i-1][ls]){
					int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
					if(val>=i){
						if(r==(1<<(i-1))){
							dp[i][j].pb({l,1<<i,val,num});
						}else{
							dp[i][j].pb(itm);
						}
					}
				}
				if(a[unival[i-1][ls]]>=i){
					// i think only here modify premax
					unival[i][j] = unival[i-1][ls];
					alltm[i][j] = alltm[i-1][ls];
					premx[alltm[i][j]+(1<<i)*j] = max(premx[alltm[i][j]+(1<<i)*j],(1<<i)*(j+1));
				}else{
					unival[i][j] = unival[i-1][rs];
					alltm[i][j] = (1<<(i-1))+alltm[i-1][rs];
					for(auto itm : dp[i-1][rs]){
						int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
						dp[i][j].pb({l+(1<<(i-1)),r+(1<<(i-1)),val,num});
					}
				}
			}else{
				alltm[i][j] = (1<<(i-1))+alltm[i-1][rs];
				for(auto itm : dp[i-1][rs]){
					int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
					if(val>=i){
						dp[i][j].pb({l+(1<<(i-1)),r+(1<<(i-1)),val,num});
					}
				}
				if(a[unival[i-1][rs]]>=i){
					unival[i][j] = unival[i-1][rs];
					for(auto itm : dp[i-1][ls]){
						int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
						if(r==(1<<(i-1))){
							dp[i][j].pb({l,alltm[i][j],val,num});
						}else{
							dp[i][j].pb(itm);
						}
					}
				}else{
					unival[i][j] = unival[i-1][ls];
					for(auto itm : dp[i-1][ls]){
						int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
						if(r==(1<<(i-1))){
							dp[i][j].pb({l,(1<<i),val,num});
						}else{
							dp[i][j].pb(itm);
						}
					}
				}
			}
			// cout<<"i="<<i<<' '<<"j="<<j<<endl;
			// cout<<alltm[i][j]<<' '<<unival[i][j]<<endl;
			// for(auto itm : dp[i][j]){
			// 	int l=itm[0],r=itm[1],val=itm[2];
				
			// }cout<<endl;
		}
		for(auto itm : dp[i][0]){
			int l=itm[0],r=itm[1],val=itm[2],num=itm[3];
			// cout<<l<<','<<r<<','<<val<<','<<itm[3]<<endl;
			if(r<=(1<<(i-1)))continue ;
			ans[max(l,(1<<(i-1)))] += num+1;
			ans[r] -= num+1;
		}
		// cout<<endl;
	}
	rep(i,1,K){
		premx[i] = max(premx[i-1],premx[i]);
	}
	rep(i,1,K)ans[i] += ans[i-1];
	ans[0] = 1;
	// rep(i,0,K){
	// 	cout<<ans[i]<<' ';
	// }cout<<endl;
	int st = 1;
	// cout<<"premx : ";
	// rep(i,0,K){
	// 	cout<<premx[i]<<' ';
	// }cout<<endl;
	rep(i,0,K){
		if(st<i+1){
			st <<= 1;
		}
		assert(premx[i]<=st);
		ans[i] += (ll)(st-premx[i])*(st+premx[i]+1)/2;
	}
	return ;
}
signed main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	n = rd();
	m = rd();
	rep(i,0,n)ya[i] = rd();
	rep(i,0,m)c[i] = rd()-1;
	K=1,lim=0;
	while(K<n){
		K <<= 1;
		lim++;
	}
	// cout<<K<<','<<lim<<endl;
	repp(i,0,lim){
		sz[i] = (1<<(lim-i));
		d[i].resize(sz[i]+2);
		dp[i].resize(sz[i]+2);
		alltm[i].resize(sz[i]+2);
		unival[i].resize(sz[i]+2);
		if(i==0)continue ;
		string s;
		cin>>s;
		rep(j,0,sz[i]){
			d[i][j] = (s[j]-'0');
		}
	}
	// cout<<"ok"<<endl;
	int T = rd();
	T = 1;
	while(T--){
		rep(i,0,4){
			X[i] = rd();
		}
		rep(i,0,n){
			a[i] = ya[i]^X[(i+1)%4];
		}
		solve();
		ll rlt = 0;
		rep(i,0,m){
			rlt ^= (i+1)*ans[i];
		}
		cout<<rlt<<endl;
	}
	return 0;
}
/*
g++ arena.cpp -o arena -g -std=c++14 -Wall -Wshadow -fsanitize=address,undefined && ./arena < in.in 
*/